package com.kc.data.scenic.controller;

import com.google.common.collect.Maps;
import com.kc.data.common.base.StringUtils;
import com.kc.data.common.core.AjaxResult;
import com.kc.data.common.core.controller.BaseController;
import com.kc.data.common.page.TableDataInfo;
import com.kc.data.common.service.IBizPlatformWalletService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Map;

/**
 * @ClassName BizPlatformWalletController
 * @Description 钱包Controller
 * @Author wangdongliang
 * @Date 2021/6/16 14:05
 */
@Slf4j
@RestController
@RequestMapping("/platformWallet")
public class BizPlatformWalletController extends BaseController {
    @Resource
    private IBizPlatformWalletService bizPlatformWalletService;
    /**
     * 钱包预览
     */
    //@PreAuthorize("@ss.hasPermi('business:platformWallet:walletOverview')")
    @PostMapping(value = "/walletOverview/{platformId}/{type}")
    public AjaxResult walletOverview(@PathVariable("platformId") Integer platformId,@PathVariable("type") Integer type){
        //获取二级商户编号
        String subMchid = bizPlatformWalletService.getSubMchid(platformId,type);
        if(StringUtils.isEmpty(subMchid)){
            return AjaxResult.error("二级商户编号错误");
        }
        Map<String, BigDecimal> result = Maps.newHashMap();
        //总收入金额
        BigDecimal totalIncome = new BigDecimal("0.0");
        totalIncome = bizPlatformWalletService.getFinishOrderMoney(platformId,-type);
        //提现中金额
        BigDecimal withdrawing = bizPlatformWalletService.getWithdrawing(subMchid);
        //已提现金额
        BigDecimal withdrew = bizPlatformWalletService.getWithdraw(subMchid);
        //可提现金额
        BigDecimal canWithdraw = bizPlatformWalletService.getCanWithdraw(subMchid);
        result.put("totalIncome", totalIncome);
        result.put("canWithdraw", canWithdraw);
        result.put("withdrawing", withdrawing);
        result.put("withdrew", withdrew);
        return AjaxResult.success(result);
    }

    //@PreAuthorize("@ss.hasPermi('business:platformWallet:walletList')")
    @PostMapping(value = "/walletList/{platformId}/{type}")
    public TableDataInfo walletList(@PathVariable("platformId") Integer platformId,@PathVariable("type") Integer type){
        //获取二级商户编号
        String subMchid = bizPlatformWalletService.getSubMchid(platformId,type);
        startPage();
        return getDataTable(bizPlatformWalletService.getWalletRecord(subMchid));
    }



}
